<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 订单管理
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\enum\OrderTypeEnum;
use app\model\Order as OrderModel;
use think\Controller;
use think\Db;

class Order extends Controller
{
  // 会员充值
  public function user()
  {
    $model = new OrderModel();
    $order = $model::with('user')
      ->where('type','=',OrderTypeEnum::MORE)
      ->order('create_time desc')
      ->paginate(20);
    $this->assign('order',$order);
    return view();
  }

  // 玻璃水
  public function bolishui()
  {
    $model = new OrderModel();
    $bolishui = $model::with(['xiche','user'])
      ->where('type','=',OrderTypeEnum::WATER)
      ->order('id desc')
      ->paginate(20);
    $this->assign('bolishui',$bolishui);
    return view();
  }

  // 洗车
  public function xiche()
  {
    $model = new OrderModel();
    $xichelog = $model::with(['user','xiche'])
      ->where('type','=',OrderTypeEnum::XICHE)
      ->order('id desc')
      ->paginate(20);
    $this->assign('xichelog',$xichelog);
    return view();
  }

  // 机油
  public function jiyou()
  {
    $model = new OrderModel();
    $jiyoulog = $model::with(['user','xiche','jiyou'])
      ->where('type','=',OrderTypeEnum::BAOYANG)
      ->order('id desc')
      ->paginate(20);
    $this->assign('jiyoulog',$jiyoulog);
    return view();
  }

  // 删除
  public function del()
  {
    if($this->request->isAjax()) {
      $id = $this->request->has('id') ? $this->request->param('id', 0, 'intval') : 0;
      if(false == Db::name('order')->where('id',$id)->delete()) {
        return $this->error('删除失败');
      } else {
        return $this->success('删除成功');
      }
    }
  }
  
}
?>